﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="StandardTeavitus", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(StandardTeavitus))]
    public class StandardTeavitusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IStandardTeavitus clazz;
        
        public StandardTeavitusSerializer(IStandardTeavitus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.ObjektID!=null) {
                Writer.WriteStartElement("ObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TeavitamiseEesmarkKL!=null) {
                Writer.WriteStartElement("TeavitamiseEesmarkKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.TeavitamiseEesmarkKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.IsikObjektID!=null) {
                Writer.WriteStartElement("IsikObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.IsikObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.IsikCSV!=null) {
                Writer.WriteStartElement("IsikCSV");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikCSV))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsutusObjektID!=null) {
                Writer.WriteStartElement("AsutusObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.AsutusObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsutusCSV!=null) {
                Writer.WriteStartElement("AsutusCSV");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsutusCSV))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Menetlused!=null) {
                Writer.WriteStartElement("Menetlused");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("Menetlus", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.Menetlused.Count);
                for (int x = 0; ((clazz.Menetlused != null) 
                            && (x < clazz.Menetlused.Count)); x = (x + 1)) {
                    if (clazz.Menetlused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaMenetlused = this.GetMetaData(clazz.Menetlused[x]);
                        Writer.WriteTypeAttribute(metaMenetlused.TypeQualifiedName.Namespace, metaMenetlused.TypeQualifiedName.Name);
                        metaMenetlused.NewSerializer(clazz.Menetlused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ObjektID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>StandardTeavitus>ObjektID");
                }
                clazz.ObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ObjektID")).Value;
            }
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="TeavitamiseEesmarkKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.TeavitamiseEesmarkKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("TeavitamiseEesmarkKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="IsikObjektID") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.IsikObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("IsikObjektID")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="IsikCSV") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.IsikCSV = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("IsikCSV")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsutusObjektID") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsutusObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("AsutusObjektID")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsutusCSV") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsutusCSV = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsutusCSV")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Menetlused") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Menetlused = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlus>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Menetlused");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaMenetlused = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlus>(Reader, "Menetlus", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlus item = metaMenetlused.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IMenetlus>();
                                clazz.Menetlused.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaMenetlused.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.Menetlused.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
